package com.demo.web.action;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import com.jweb.framework.InstanceFactory;
import com.jweb.framework.db.JdbcTemplate;
import com.jweb.framework.mvc.annotation.Controller;
import com.jweb.framework.mvc.annotation.Request;
import com.jweb.framework.mvc.bean.View;
import com.jweb.framework.util.UUIDUtil;

@Controller
public class MobileAction {

	
	@Request.Get("/m/home")
	public View home() {
		return new View();
	}
	
	private JdbcTemplate jdbc=InstanceFactory.getDataSourceFactory().getJdbcTemplate();
	
	@Request.Get("/m/ajax/{type}/{step}")
	public View ajajInfo(String type,int step) throws Exception {
		View v = null; 
		Map<String,Object> data=new HashMap<String, Object>();
		if("news".equals(type)){
			v= new View("m/ajax/news");
			data.put("rodom", UUIDUtil.getUUID(5,62));
			data.put("step", step);
		}if("company".equals(type)){
			v= new View("m/ajax/company");
			List<Map<String, Object>> list=jdbc.queryList("SELECT * FROM  pay_company", null);
			data.put("list", list);
		}
		v.setData(data);
		return v;
	}
	
	@Request.Get("/m/page/{type}/{id}")
	public View toPage(String type,int id) throws Exception {
		View v = null; 
		Map<String,Object> data=new HashMap<String, Object>();
		if("company".equals(type)){
			v= new View("m/page/company");
			Map<String, Object> map=jdbc.query("SELECT * FROM  pay_company where companyId=?", new Object[]{id});
			data.put("bean", map);
		}
		v.setData(data);
		return v;
	}
}
